 var no=1;
webix.ready(function(){
 
    var data = [
        {"code":"cpu","name":"error"},
        {"code":"cpu","name":"error"},
        {"code":"cpu","name":"ok"},
        {"code":"cpu","name":"error"},
        {"code":"cpu","name":"ok"}

    ];
    var my_template={ 
              template: "<span style='font-size:20px; font-weight:bold; color:#3498DB'; >终端状况</span>&nbsp;/&nbsp;&nbsp; TerminalState",
              height:45,
              borderless:true
            };
    var my_toolbar={
        view:"toolbar",
        elements:[           
          {
            view:"text",
            id:"s1",
            label:"终端号：",
            width:300
          },
          {
            view:"text",
            id:"s2",
            label:"终端名称:",
            labelWidth:105,
            width:300
          },
          {view:"button",value:"查询",width:50,click:"select",css:"btn_check"}
        ]   
      };
    var my_table={
                view:"dataview",
                height:1200,
                scroll:false,
                id:"dataviewC",
                borderless:true,
                type:{ 
                    width:300,
                    height:300,
                    template:function(obj){
                        if(obj.report=='1001'){
                            return "<div class='overall' ><div id='sign1'></div><img src='/customer_plat/public/images/guizi.png'/></div><div>终端号："+obj.terminal_id+"</div><div>终端名称："+obj.terminal_id+"</div><button class='' style='cursor:pointer;' onclick=\"detail('"+obj.terminal_id+"');\">查看详情</button> <button class='' style='cursor:pointer;' onclick=\"inventory('"+obj.terminal_id+"');\">查看当前库存</button>";   
                        }else{
                            return "<div class='overall' ><div id='sign2'></div><img src='/customer_plat/public/images/guizi.png'/></div><div>终端号："+obj.terminal_id+"</div><div>终端名称："+obj.terminal_id+"</div><button class='' style='cursor:pointer;' onclick=\"detail('"+obj.terminal_id+"');\">查看详情</button> <button class='' style='cursor:pointer;' onclick=\"inventory('"+obj.terminal_id+"');\">查看当前库存</button>";
                        }
                        if(obj.state==1){
                        }
                    }
                },
                url:"getTerminalList"
            };

    var myDetail={
              view:"datatable",
              id:"table",
              height:250,
              css:"tableC",
              // hidden:true,
              type:{
                       votes_color:function(obj,type){
                            return  (obj.name =="1000"?"green":"red")
                        }
                    },
              columns:[
                {id:"No",header:"序号",width:60,
                    template:function(obj,type){
                      return no++;
                    }
                },
                {id:"code",header:"部件代码",fillspace:true},
                {id:"name",header:"部件名称",fillspace:true},
                {id:"status",header:"状态",fillspace:true, 
                    template:function(obj,type){
                    	var msg = "OK";
                    	var cr = "green";
                    	if(obj.status==1001){
                    		msg = "ERROR";
                    		cr = "red";
                    	}
                    	
                        return "<span style='color:"+cr+
                            "'>"+msg+"</span>";
                    }
                },
                {id:"msg",header:"详情",fillspace:true, 
                	template:function(obj,type){
	                	var cr = "green";
	                	if(obj.status==1001){
	                		cr = "red";
	                	}
                	
                    return "<span style='color:"+cr+
                        "'>"+obj.msg+"</span>";
                }}
              ],
              data:data
            };
    var my_inventry={
            view:"datatable",
            id:"my_inventry",     
            columns:[
              {id:"material_id",header:"供应商系统编码",fillspace:true},
              {id:"cust_cutter_spesc_id",header:"客户系统编码",fillspace:true},
              {id:"cutter_specs",header:"规格",fillspace:true,editor:"text"},
              {id:"simple_specs_cust",header:"规格简称",fillspace:true,editor:"text"},
              {id:"supp_name",header:"供应商",fillspace:true,editor:"text"},
              {id:"safeNum",header:"安全数量",fillspace:true,editor:"text"},
              {id:"operate",header:"操作",fillspace:true,template:"<div><span class='padding_less'><a href='#' onclick=\"delRow('#material_id#')\">删除</a></span>&nbsp;&nbsp;&nbsp<a href='#' onclick=\"edit('#material_id#');\">编辑</a></div>"}
            ],
            height:600,      
            select:true,
          };
   
 
    var body=new webix.ui({
        fullscreen:true,
        container:"body",
        type:"line",
        id:"mylayout",
        margin:10,
        rows:[
            my_template,
//            my_toolbar,
            my_table,
            myDetail
        ]//----rows结束----
    });//---webix.ui结束---- 
   
 $$('table').hide();
 //设置dataview高度
$(".overall").parent().parent().height(350);

});

function callback(data){
  var text1=JSON.parse(data); 
  var data = new webix.DataCollection({data:text1.page});
  $$('mydatatable').data.sync(data);
  $$("pagerA").define("limit",text1.totalPageCount);
  $$("pagerA").define("count",text1.totalCount);
  $$("pagerA").define("size",text1.pageSize);
  $$("pagerA").define("page",text1.currPage-1);
  $$('pagerA').refresh();
}
function detail(teminal_id){
	var params = {};
	params["terminal_id"] = teminal_id;
 	webix.ajax().sync().post("getTerminalInfoByTerminalId", params,function(text, xml, xhr) {
           var tableValues1 = $.parseJSON(text);
           no=1;
          var dataDetail = new webix.DataCollection({data:tableValues1});
          $$('table').data.sync(dataDetail);
          $$("table").show();
    });
}

function inventory(teminal_id){
	layer.open({
        type: 2,
        //skin: 'layui-layer-lan',
        title: false,
        area: ['1000px', '670px'],
        content: "terminaInventoryIndex?terminal_id="+teminal_id,
        end: function(){
        }
    });
}
//查询实现
function select(){
  params="";
  var s1=$$("s1").getValue();
  var s2=$$("s2").getValue();
  params=s1+"#"+s2;
  // alert(params);
  if(params=="#"){
    alert("请输入查询条件");
  }
  else{
    postData("",params,callback);
  }
  
}